package org.aurora.six;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author : Aurora
 * @date : 4/7/24 2:17 AM
 * @description  条件变量支持
 */
public class AQSConditionalVariable {

    void methodOne(){
        ReentrantLock lock = new ReentrantLock();//(1)
        Condition condition = lock.newCondition();//(2)
        lock.lock();//(3)
        try{
            System.out.println("begin wait");
            condition.await();//(4)
            System.out.println("end wait");
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            lock.unlock();//(5)
        }
        lock.unlock();//(6)
        try{
            System.out.println("begin signal");
            condition.signal();//(7)
            System.out.println("end signal");
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            lock.unlock();//(8)
        }

    }

    public static void main(String[] args) {
        ReentrantLock reentrantLock = new ReentrantLock();
    }

}
